package com.huaxiafinance.management.controller;

import com.huaxiafinance.management.dto.request.QueryWithdrawalsAuditDto;
import com.huaxiafinance.management.dto.request.UpdateStateWithDto;
import com.huaxiafinance.management.service.WithdrawalsAuditService;
import com.huaxiafinance.management.util.MessageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;

@Controller("withdrawalsAuditController")
@RequestMapping("/withdrawalsAudit")
public class WithdrawalsAuditController {

  @Autowired
  private WithdrawalsAuditService withdrawalsAuditService;

  /**
   * 获得提现审核列表
   */
  @RequestMapping(value = "/queryWithdrawalsList", produces = "application/json; charset=utf-8")
  public @ResponseBody
  String queryWithdrawalsList(QueryWithdrawalsAuditDto dto) {

    return withdrawalsAuditService.queryWithdrawalsList(dto).getAsJSON();
  }

  /**
   * 获得审核回显
   */
  @RequestMapping(value = "/getInfo", produces = "application/json; charset=utf-8")
  public @ResponseBody
  String getInfo(Integer id) {
    return withdrawalsAuditService.getInfo(id).getAsJSON();
  }

  /**
   * 修改审核状态
   */
  @RequestMapping(value = "/updateState", produces = "application/json; charset=utf-8")
  public @ResponseBody
  String updateState(@Valid UpdateStateWithDto dto, BindingResult bindingResult) {
    MessageResult result = withdrawalsAuditService.updateState(dto);
    if (bindingResult.hasErrors()) {
      result.setFailureResult(bindingResult);
    }
    return result.getAsJSON();
  }


  @RequestMapping(value = "/showRule", produces = "application/json; charset=utf-8")
  public @ResponseBody
  String showRule() {
    return withdrawalsAuditService.showRule().getAsJSON();
  }


  @RequestMapping(value = "/updateRule", produces = "application/json; charset=utf-8")
  public @ResponseBody
  String updateRule(String cycle, String second, String minimumAmount) {
    return withdrawalsAuditService.updateRule(cycle, second, minimumAmount).getAsJSON();
  }

}
